<template>
    <view class="content">
		<view class="weixin-tip" >
		    <image src="/static/llq.png" mode="widthFix">
				<view class="wctxt" @click="goBack">
					<text>已完成支付？点击此链接返回订单列表页</text>
				</view>
		</view>
    </view>
</template>

<script>
const app = getApp();
var util = require('../utils/util.js');
export default {
    data() {
        return {
			checks:false,
			order_number:'',
			type:'',
			payment:''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        var that = this;
		this.order_number = options.order_number
		this.type = options.type
		this.payment = options.payment
		if(options.payment=='alipay'){
			if(util.isWechat()==true){
				
			}else{
				this.orderPayByOrderNumber()
			}
		}else{
			if(util.isWechat()==true){
				
			}else{
				this.orderPayByOrderNumbers()
			}
		}
		
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
		goBack(){
			uni.navigateTo({
				url:'/pages/order/order?type=0'
			})
		},
		orderPayByOrderNumber(){
			const that =this;
			var url = this.type==1?'User/orderAliByOrderNumber':'User/orderAliByOrderId'
			if(this.type==1){
				var data = {order_number:this.order_number}
			}else{
				var data = {id:this.order_number}
			}
			app.globalData.api.request(url,data , 'post', 'form').then((res) => {
				if (res.code == 0) {
					// #ifdef H5
					uni.setStorageSync('paytype', 1)
					window.open(res.data,'_self');
					// #endif
				}else{
					app.globalData.show(res.msg)
				}
			});
		},
		
		orderPayByOrderNumbers(){
			const that =this;
			var url = this.type==1?'User/orderPayByOrderId':'User/orderPayByOrderNumber'
			if(this.type==1){
				var data = {order_number:this.order_number}
			}else{
				var data = {id:this.order_number}
			}
			app.globalData.api.request(url,data , 'post', 'form').then((res) => {
				if (res.code == 0) {
					// #ifdef H5
					uni.setStorageSync('paytype', 1)
					const referer = 'https://saas.mmchengren.com';
					const url = res.data.h5_url;
														 
					// 创建一个新的URL对象
					const urlObj = new URL(url);
														 
					// 使用自定义的URLSearchParams来设置headers
					const params = new URLSearchParams(urlObj.search);
					params.set('Referer', referer);
					// 使用新的URL对象来构建带有headers的URL
					urlObj.search = params.toString();
					console.log(urlObj.toString())
					// 导航到支付链接
					window.location.href = urlObj.toString();
					// #endif
				}else{
					app.globalData.show(res.msg)
				}
			});
		},
	}
};
</script>
<style lang="scss">
	.wctxt{
		position: fixed;
		width: 100%;
		height: auto;
		display: table;
		text-align: center;
		top: 40%;
		left: 0px;
		font-size: 28rpx;
		color: rgba(255, 228,2, 1);
		text{
			text-decoration: underline;
		}
	}
	page{
		background-color: #f6f6f6;
	}
	.content {
		width: 100%;
		height: auto;
		display: table;
		box-sizing: border-box;
		padding: 20px 24rpx;
		background-color: #fff;
	}
</style>
